import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class User {
    private String username;
    private String password;
    private String name;
    private String idCard;
    private int age;
    private String phoneNumber;
    private String postalCode;
    private String email;

    // 构造函数、getter和setter方法省略，自行实现

    public boolean isValidUsername() {
        String regex = "^[A-Za-z][A-Za-z0-9_]*$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(username);
        return matcher.matches();
    }

    public boolean isValidPassword() {
        String regex = ".{8,}"; // 至少8位任意字符
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(password);
        return matcher.matches();
    }

    public boolean isValidName() {
        String regex = "^[\\u4e00-\\u9fa5A-Za-z]+$"; // 仅包含中文或英文字母
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(name);
        return matcher.matches();
    }

    public boolean isValidIdCard() {
        // 简化版正则表达式，实际验证可能更复杂
        String regex = "^(?!0)\\d{17}[0-9X]$|^\\d{15}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(idCard);
        return matcher.matches();
    }

    public boolean isValidAge() {
        return age >= 0 && age < 150;
    }

    public boolean isValidPhoneNumber() {
        // 简化版正则表达式，实际验证可能更复杂
        String regex = "^(1\\d{10})|(\\d{3,4}-\\d{7,8})$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }

    public boolean isValidPostalCode() {
        String regex = "^[1-9]\\d{5}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(postalCode);
        return matcher.matches();
    }

    public boolean isValidEmail() {
        String regex = "^[\\w-]+(\\.[\\w-]+)*@([\\w-]+\\.)+[a-zA-Z]{2,7}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    // toString方法省略，自行实现
}
